// 获取用户头像，并进行头像的全局设置
// 选从本地localStorage获取，有则全局设置
// 若本地没有则，从后端获取，若有则返回并 保存在localStorage,同时全局设置
// 若没有，则使用默认头像
// import photo from "../img/user-photo.png"

export default function setPublicUserPhoto(_this) {
    var localPhoto = localStorage.getItem("userPhoto");
    if (localPhoto != null) {
        _this.$store.commit("setUserPhoto", localPhoto);
    } else {
        _this.$http.post("readUserPhoto").then(response => {
            // console.log(response);
            if (response.bodyText != "" && response.bodyText != "null") {
                localStorage.setItem("userPhoto", response.bodyText);
                _this.$store.commit("setUserPhoto", response.bodyText);
            } else {
                _this.$store.commit(
                    "setUserPhoto",
                    'img/user-photo.png'
                );
            }
        });
    }
}